import request from '../utils/request'

/**
 * 点赞回答
 * @param {Object} data - 点赞数据 {answerId, voteType} 
 * @returns {Promise}
 */
export function voteAnswer(data) {
  if (!data.answerId) {
    return Promise.reject(new Error('回答ID不能为空'))
  }
  
  return request({
    url: '/votes',
    method: 'post',
    data
  })
}

/**
 * 取消点赞
 * @param {Number} answerId - 回答ID
 * @returns {Promise}
 */
export function cancelVote(answerId) {
  if (!answerId) {
    return Promise.reject(new Error('回答ID不能为空'))
  }
  
  return request({
    url: `/votes/answer/${answerId}`,
    method: 'delete'
  })
}

/**
 * 检查点赞状态
 * @param {Number} answerId - 回答ID
 * @returns {Promise}
 */
export function checkVoteStatus(answerId) {
  if (!answerId) {
    return Promise.reject(new Error('回答ID不能为空'))
  }
  
  return request({
    url: `/votes/answer/${answerId}/status`,
    method: 'get'
  })
}

/**
 * 获取用户点赞的回答列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getUserVotedAnswers(params = {}) {
  return request({
    url: '/votes/my',
    method: 'get',
    params
  })
} 